package com.aat.dxfy.jdbc.datasource;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.aat.dxfy.utils.Atools;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class PuaTest {
	private static String driver="com.mysql.jdbc.Driver";
	private static String jdbcUrl="jdbc:mysql://127.0.0.1:3306/pua?useUnicode=true&characterEncoding=utf8";
	private static String user="root";
	private static String passwd="root";
	
	public static void main(String[] args) throws SQLException {
		HikariConfig config = new HikariConfig();
		config.setMinimumIdle(1);
		config.setMaximumPoolSize(100);
		config.setDriverClassName(driver);
		config.setJdbcUrl(jdbcUrl);
		config.setUsername(user);
		config.setPassword(passwd);
		HikariDataSource dataS2 = new HikariDataSource(config);

		// action
		String sql="select title,content from article_b";
		Connection conn = dataS2.getConnection();
		PreparedStatement ps=conn.prepareStatement(sql);
		ResultSet rs=ps.executeQuery();
		int c=1;
		while(rs.next()){
			String s0=rs.getString(1);
			String s1=rs.getString(2);
			Atools.writeS(s1, "utf-8", "tmp.txt");
			Atools.writeStrAppend("pua.txt", c+s0+"\n"+readLine("tmp.txt")+"\n\n\n");
			c++;
		}
		dataS2.close();
	}
	
	public static String readLine(String file) {
		try {
			BufferedReader br=new BufferedReader(new FileReader(file));
			br.readLine();
			br.readLine();
			br.readLine();
			String s=null;
			String res="";
			while((s=br.readLine())!=null){
				s = s.trim();
				res+=s+"\n";
			}
			
			String[] ss =res.split("\n");
			String rr="";
			for (int j=0;j< ss.length-2;j++) {
				String s1 =ss[j];
				rr+=s1+"\n";
			}
			br.close();
			return rr;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

}
